package com.cdc.baserecyclerviewadapterhelper.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.cdc.baserecyclerviewadapterhelper.R;
import com.cdc.baserecyclerviewadapterhelper.activity.multi.ChooseMultipleItemUseTypeActivity;
import com.cdc.baserecyclerviewadapterhelper.activity.node.ChooseNodeUseTypeActivity;
import com.cdc.baserecyclerviewadapterhelper.adapter.HomeAdapter;
import com.cdc.baserecyclerviewadapterhelper.databinding.ActivityHomeBinding;
import com.cdc.baserecyclerviewadapterhelper.entity.HomeEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

public class HomeActivity extends AppCompatActivity implements OnItemClickListener {

    private ActivityHomeBinding mViewBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater layoutInflater = LayoutInflater.from(this);
        mViewBinding = ActivityHomeBinding.inflate(layoutInflater);
        setContentView(mViewBinding.getRoot());


       HomeAdapter  homeAdapter =new HomeAdapter(getHomeEntity());
       homeAdapter.setAnimationEnable(true);
       View topView=LayoutInflater.from(this).inflate(R.layout.top_view, mViewBinding.recyclerView, false);
        homeAdapter.addHeaderView(topView);
        homeAdapter.setOnItemClickListener(this);

        mViewBinding.recyclerView.setAdapter(homeAdapter);



    }

    private List<HomeEntity> getHomeEntity() {
        List<HomeEntity> lists = new ArrayList<HomeEntity>();
        HomeEntity homeEntity1 = new HomeEntity("BaseQuickAdapter 基础功能");
        HomeEntity homeEntity11 = new HomeEntity("Animation", AnimationUseActivity.class, R.mipmap.gv_animation);
        HomeEntity homeEntity12 = new HomeEntity("Header/Footer", HeaderAndFooterUseActivity.class, R.mipmap.gv_header_and_footer);
        HomeEntity homeEntity13 = new HomeEntity("EmptyView", EmptyViewUseActivity.class, R.mipmap.gv_empty);
        HomeEntity homeEntity14 = new HomeEntity("ItemClick", ItemClickActivity.class, R.mipmap.gv_item_click);
        HomeEntity homeEntity15 = new HomeEntity("DataBinding", DataBindingUseActivity.class, R.mipmap.gv_databinding);
        HomeEntity homeEntity16 = new HomeEntity("DiffUtil", DiffUtilActivity.class, R.mipmap.gv_databinding);

        HomeEntity homeEntity2 = new HomeEntity("Adapter 类型");

        HomeEntity homeEntity21 = new HomeEntity("MultipleItem", ChooseMultipleItemUseTypeActivity.class, R.mipmap.gv_multipleltem);


        HomeEntity homeEntity22 = new HomeEntity("Quick Section", SectionQuickUseActivity.class, R.mipmap.gv_section);
        HomeEntity homeEntity23 = new HomeEntity("Node", ChooseNodeUseTypeActivity.class, R.mipmap.gv_expandable);

        HomeEntity homeEntity3 = new HomeEntity("功能模块");
        HomeEntity homeEntity31 = new HomeEntity("LoadMore", LoadMoreRefreshUseActivity.class, R.mipmap.gv_pulltorefresh);
        HomeEntity homeEntity32 = new HomeEntity("DragAndSwipe", DragAndSwipeUseActivity.class, R.mipmap.gv_drag_and_swipe);
        HomeEntity homeEntity33 = new HomeEntity("UpFetch", UpFetchUseActivity.class, R.drawable.gv_up_fetch);

        lists.add(homeEntity1);
        lists.add(homeEntity11);
        lists.add(homeEntity12);
        lists.add(homeEntity13);
        lists.add(homeEntity14);
        lists.add(homeEntity15);
        lists.add(homeEntity16);
        lists.add(homeEntity2);
        lists.add(homeEntity21);
        lists.add(homeEntity22);
        lists.add(homeEntity23);
        lists.add(homeEntity3);
        lists.add(homeEntity31);
        lists.add(homeEntity32);
        lists.add(homeEntity33);
        return lists;
    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        HomeEntity homeEntity= (HomeEntity) adapter.getData().get(position);
        if (!homeEntity.isHeader()) {
            startActivity(new Intent(HomeActivity.this, homeEntity.getActivity()));
        }
    }
}
